/*
Copyright 2010 Christian Dadswell
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package subscriber.chrisdadswell.co.uk; 

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
 
public class Activity_Preferences extends PreferenceActivity {
	
    public static final String _APP_TAG = "Activity_Preferences"; 
	public String _TOKEN = null;
	public String _USERNAME = null;
	public String _PASSWORD = null;
	SharedPreferences preferences;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
        addPreferencesFromResource(R.xml.preferences);
        
        final Preference prefGoogleUser = (Preference) findPreference("prefGoogleUser");
        prefGoogleUser.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        	public boolean onPreferenceClick(Preference preference) {
        		
        		//Toast.makeText(getBaseContext(),"Username clicked",Toast.LENGTH_SHORT).show();
        		SharedPreferences customSharedPreference = getSharedPreferences("myCustomSharedPrefs", Activity.MODE_PRIVATE);
        		SharedPreferences.Editor editor = customSharedPreference.edit();
        		editor.putString("myCustomPref","The preference has been clicked");
        		editor.commit();
        		return true;
        	}
        });
        
        Preference prefGooglePassword = (Preference) findPreference("prefGooglePassword");
        prefGooglePassword.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        	public boolean onPreferenceClick(Preference preference) {
        		
        		
        		//Toast.makeText(getBaseContext(),"Password clicked",Toast.LENGTH_SHORT).show();
        		SharedPreferences customSharedPreference = getSharedPreferences("myCustomSharedPrefs", Activity.MODE_PRIVATE);
        		SharedPreferences.Editor editor = customSharedPreference.edit();
        		editor.putString("myCustomPref","The preference has been clicked");
        		editor.commit();
        		return true;
        	}
        });
        
// APPLICATION
        
        Preference prefSupport = (Preference) findPreference("prefSupport");
        prefSupport.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        
        	public boolean onPreferenceClick(Preference preference) {
				Intent intent = new Intent(Intent.ACTION_VIEW); 
				intent.setData(Uri.parse("http://www.chrisdadswell.co.uk/subscriber/support"));
				startActivity(intent);
		    	
        		//Toast.makeText(getBaseContext(),"About clicked",Toast.LENGTH_SHORT).show();
        		SharedPreferences customSharedPreference = getSharedPreferences("myCustomSharedPrefs", Activity.MODE_PRIVATE);
        		SharedPreferences.Editor editor = customSharedPreference.edit();
        		editor.putString("myCustomPref","The preference has been clicked");
        		editor.commit();
        		return true;
        	}
        });
        
        Preference prefChangelog = (Preference) findPreference("prefChangelog");
        prefChangelog.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        	public boolean onPreferenceClick(Preference preference) {
		    	Intent intentChangeLog = new Intent(Activity_Preferences.this, Activity_ChangeLog.class);
		    	Activity_Preferences.this.startActivity(intentChangeLog);
        		
        		//Toast.makeText(getBaseContext(),"Changelog clicked",Toast.LENGTH_SHORT).show();
        		SharedPreferences customSharedPreference = getSharedPreferences("myCustomSharedPrefs", Activity.MODE_PRIVATE);
        		SharedPreferences.Editor editor = customSharedPreference.edit();
        		editor.putString("myCustomPref","The preference has been clicked");
        		editor.commit();
        		return true;
        	}
        });
        
        Preference prefAbout = (Preference) findPreference("prefAbout");
        prefAbout.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        	public boolean onPreferenceClick(Preference preference) {
		    	Intent intentAbout = new Intent(Activity_Preferences.this, Activity_About.class);
		    	Activity_Preferences.this.startActivity(intentAbout);
		    	
        		//Toast.makeText(getBaseContext(),"About clicked",Toast.LENGTH_SHORT).show();
        		SharedPreferences customSharedPreference = getSharedPreferences("myCustomSharedPrefs", Activity.MODE_PRIVATE);
        		SharedPreferences.Editor editor = customSharedPreference.edit();
        		editor.putString("myCustomPref","The preference has been clicked");
        		editor.commit();
        		return true;
        	}
        });
	}
	
	public void onStart() {
		super.onStart();
	}

	//Toast.makeText(this, ".. onStart ..", Toast.LENGTH_SHORT).show();
	
	public void onRestart() {
		super.onRestart();
		//Toast.makeText(this, ".. onReStart ..", Toast.LENGTH_SHORT).show();
	}
   
	public void onResume() {
		super.onResume();
		//Toast.makeText(this, ".. onResume ..", Toast.LENGTH_SHORT).show();
	}
   
	public void onPause() {
		super.onPause();
		//Toast.makeText(this, ".. onPause ..", Toast.LENGTH_SHORT).show();
   	
	}
   
	public void onStop() {
		super.onStop();
		//Toast.makeText(this, ".. onStop ..", Toast.LENGTH_SHORT).show();
	}
	
	public void onDestroy() {
		super.onDestroy();
		//Toast.makeText(this, ".. onDestroy ..", Toast.LENGTH_SHORT).show();
	}
}